type Tree = {
  value: string;
  children: Array<Tree>;
};

const obj: Tree = {
  // 数据结构 : 树
  value: "1", // 此处的值是根据Tree里面的泛型规定的类型
  children: [
    {
      value: "2",
      children: [
        {
          value: "3",
          children: [
            {
              value: "4",
              children: [
                {
                  value: "5",
                  children: [],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      value: "4",
      children: [],
    },
  ],
};
type IRes = Array<{ code: number; data: Array<{ data: string }> }>;

// 函数返回值 Promsie类型
function returnPromise(a?: string | undefined): Promise<IRes> {
  // Promise<IRes> 和 Promise
  // 添加Promise类型
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve([{ code: 200, data: [{ data: "hello" }, { data: "bad" }] }]);
    }, 200);
  });

  // 这种Promise的写法就不用约束了 : ts会自动推断
  // return Promise.resolve([{ code: 200, data: [{ data: "json" }] }]);
}

//[{ code: 200, data: [{data:"json"}] }]

returnPromise().then((res) => {
  // ts : 约束res的类型
  // [{ code: 200, data: [{ data: "json" }] }]
  console.log(res.map((item) => item.data.filter((item) => item.data)));
});

interface InFo{
  name : string;
  avator : string;
  time : string;
}
interface Ques {
  questions: {
    title: string;
    picture: Array<string>;
  };
}
interface Answer {
  answers: {
    text: string;
    audio: {
      url: string;
      total: number;
    };
  };
}
// 交叉类型 & : 合并类型   联合类型 |  : 其中之一
interface Questions {
  asker: InFo & Ques;
  answer: InFo & Answer;
}

type AskConfigList = Array<Questions>;

const arrList: AskConfigList = [
  {
    asker: {
      name: "张三",
      avator: "https://img.yzcdn.cn/vant/cat.jpeg",
      time: "2020-06-24",
      questions: {
        title: "你是谁",
        picture: [
          "https://img.yzcdn.cn/vant/cat.jpeg",
          "https://img.yzcdn.cn/vant/cat.jpeg",
          "https://img.yzcdn.cn/vant/cat.jpeg",
        ],
      },
    },
    answer: {
      name: "李四",
      avator: "https://img.yzcdn.cn/vant/cat.jpeg",
      time: "2020-06-24",
      answers: {
        text: "我是李四",
        audio: {
          url: "https://img.yzcdn.cn/vant/cat.jpeg",
          total: 10,
        },
      },
    },
  },
];
